<script setup lang="ts" name="JobLogDetail">
import { getJobLogApi } from "@/api/monitor/jobLog";

const { sys_job_group, sys_common_status } = useDict("sys_job_group", "sys_common_status");

const emit = defineEmits(['closeDialog']);

const props = defineProps({
  id: {
    type: Number,
    default: null,
  },
  title: {
    type: String,
    default: false,
  }
});

const open = ref(false);

const form = ref<JobLogRecord>({});

/** 获取调度日志详情 */
function getData() {
  if (isEmpty(props.id)) {
    open.value = true;
  } else {
    getJobLogApi(props.id).then(response => {
      form.value = response.data;
      open.value = true;
    }).catch(err => {
      console.error(err)
      closeDialog(false);
    })
  }
}

/** 关闭弹窗 */
function closeDialog(refresh: boolean) {
  open.value = false;
  emit("closeDialog", refresh);
}

watch(open, (val) => {
  if (!val) {
    closeDialog(false);
  }
});

getData();
</script>

<template>
  <!-- 调度日志详情对话框 -->
  <el-dialog :title="title" v-model="open" width="700px" append-to-body>
    <div class="detail-form">
      <el-form ref="jobLogForm" :model="form" label-width="80px">
        <el-form-item label="日志编号" prop="jobLogId">
          {{ form.jobLogId }}
        </el-form-item>
        <el-form-item label="任务名称" prop="jobName">
          {{ form.jobName }}
        </el-form-item>
        <el-form-item label="任务分组" prop="jobGroup">
          <dict-tag :options="sys_job_group" :value="form.jobGroup" />
        </el-form-item>
        <el-form-item label="执行时间" prop="createTime">
          {{ form.createTime }}
        </el-form-item>
        <el-form-item label="执行状态" prop="status">
          <dict-tag :options="sys_common_status" :value="form.status" />
        </el-form-item>
        <el-form-item label="调用方法" prop="invokeTarget">
          {{ form.invokeTarget }}
        </el-form-item>
        <el-form-item label="日志信息" prop="jobMessage" class="item-describe">
          {{ form.jobMessage }}
        </el-form-item>
        <el-form-item label="异常信息" prop="exceptionInfo" class="item-describe">
          {{ form.exceptionInfo }}
        </el-form-item>
      </el-form>
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="closeDialog(false)">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<style lang="scss" scoped>

</style>